Skip to content

Python: Fix as_agent function invocation config#6322

Closed
puneetdixit200 wants to merge 1 commit into
microsoft:mainfrom
puneetdixit200:fix-as-agent-function-invocation-config
Closed

Python: Fix as_agent function invocation config#6322
puneetdixit200 wants to merge 1 commit into
microsoft:mainfrom
puneetdixit200:fix-as-agent-function-invocation-config

Conversation

@puneetdixit200

Copy link
Copy Markdown

Motivation and Context

Fixes #6313.

BaseChatClient.as_agent() accepts function_invocation_configuration, but passing it currently raises Agent.__init__() got an unexpected keyword argument 'function_invocation_configuration' before an agent can be created.

Description

  • Add agent-level function invocation configuration support to RawAgent and Agent.
  • Forward the normalized agent-level config to clients whose get_response() accepts a per-call function invocation override, without mutating shared client defaults.
  • Use a per-call effective configuration inside FunctionInvocationLayer.get_response().
  • Add a regression test for as_agent(function_invocation_configuration=...).

Focused local tests for core clients, agents, and function invocation passed, and targeted Ruff format/lint checks passed. A local pyright -P core run is blocked in this environment by missing optional OTLP exporter imports in observability.py.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

Copilot AI review requested due to automatic review settings June 4, 2026 05:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR adds support for passing a per-call function_invocation_configuration from agents into the function-invocation layer, allowing agent instances (and as_agent(...)) to override tool/function-calling behavior for a single run without mutating the underlying client.

Changes:

  • Adds function_invocation_configuration as an optional parameter to FunctionInvocationLayer.get_response(...) and threads it through tool-calling logic via an “effective config”.
  • Introduces agent-level function_invocation_configuration plumbing and forwards it to clients that support it.
  • Adds a unit test verifying that as_agent(...) forwards configuration without mutating the base client’s configuration.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.

File Description
python/packages/core/tests/core/test_clients.py Adds a regression test ensuring agent forwarding of function invocation config.
python/packages/core/agent_framework/_tools.py Adds per-call override support for function invocation configuration inside get_response.
python/packages/core/agent_framework/_agents.py Adds agent-level config storage and conditional forwarding to get_response.
Comments suppressed due to low confidence (1)

python/packages/core/agent_framework/_agents.py:2

  • Agent currently normalizes function_invocation_configuration even when the constructor argument is None, and then always forwards it to FunctionInvocationLayer.get_response. This unintentionally overrides the client’s own self.function_invocation_configuration (e.g., a client configured with enabled=False would be re-enabled by the agent defaults). To preserve existing behavior, keep the agent’s configuration as None unless explicitly provided, and only forward function_invocation_configuration when an override is present (and adjust the run-context type accordingly).

Comment on lines +746 to +748
self.function_invocation_configuration = normalize_function_invocation_configuration(
function_invocation_configuration
)
Comment on lines +174 to +179
def _accepts_function_invocation_configuration(client: SupportsChatGetResponse[Any]) -> bool:
"""Return whether the client's get_response accepts per-call function invocation config."""
try:
return "function_invocation_configuration" in signature(client.get_response).parameters
except (TypeError, ValueError):
return False
Comment on lines +1014 to +1015
function_invocation_configuration_kwargs: dict[str, Any] = {}
if isinstance(self.client, FunctionInvocationLayer) and _accepts_function_invocation_configuration(self.client):
Comment on lines +80 to +82
async def test_base_client_as_agent_forwards_function_invocation_configuration(
chat_client_base: SupportsChatGetResponse,
) -> None:
Comment on lines +96 to +98
agent = chat_client_base.as_agent(function_invocation_configuration={"include_detailed_errors": True})

await agent.run("hello")

assert captured_config["include_detailed_errors"] is True
assert captured_config["enabled"] is True
assert chat_client_base.function_invocation_configuration["include_detailed_errors"] is False # type: ignore[attr-defined]
@moonbox3 moonbox3 added the python Issues related to the Python codebase label Jun 4, 2026
@eavanvalkenburg

Copy link
Copy Markdown
Member

Thanks for the work on this! We ended up taking a different, smaller approach for #6313, so I’m closing this PR in favor of that path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Issues related to the Python codebase

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: function_invocation_configuration from BaseChatClient.as_agent doesn't work

4 participants